package com.hengxinguotong.zhihuichengjian.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.LiftViolation;
import com.hengxinguotong.zhihuichengjian.treeview.RecyclerAdapter;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @CopyRight 恒信国通信息科技
 * @Author WuLei
 * @Date 2019/2/25
 *
 * 塔吊详情违章列表适配器
 */

public class LiftDataLiftRecycleListAdapter extends RecyclerAdapter<LiftViolation, LiftDataLiftRecycleListAdapter.LiftDataLiftRecycleListViewHolder> {

    public LiftDataLiftRecycleListAdapter(Context context, List<LiftViolation> dataList) {
        super(context, dataList);
    }

    @Override
    public LiftDataLiftRecycleListViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.item_lift_data_list_lift_recycle, null);
        return new LiftDataLiftRecycleListViewHolder(view);
    }

    @Override
    public void onBindViewHolder(LiftDataLiftRecycleListViewHolder holder, int position) {
        holder.bindData(position);
    }

    public class LiftDataLiftRecycleListViewHolder extends RecyclerAdapter.BaseViewHolder<LiftViolation>{
        @BindView(R.id.lift_status_tv)
        HXTextView liftStatusTv;
        @BindView(R.id.lift_driver_tv)
        HXTextView liftDriverTv;
        @BindView(R.id.person_count_tv)
        HXTextView personCountTv;
        @BindView(R.id.lift_tilt_tv)
        HXTextView liftTiltTv;
        @BindView(R.id.create_time_tv)
        HXTextView createTimeTv;

        public LiftDataLiftRecycleListViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        @Override
        public void bindData(int position) {
            final LiftViolation liftViolation = dataList.get(position);
            if(liftViolation.getIsIllegal() == 1){//是否违章 0正常 1违章
                liftStatusTv.setEnabled(false);
                liftStatusTv.setText("违章");
            }else {
                liftStatusTv.setEnabled(true);
                liftStatusTv.setText("正常");
            }
            liftDriverTv.setText("驾驶员：" + liftViolation.getDriverName());
            personCountTv.setText("人数：" + liftViolation.getLoadPersons() + "人");
            liftTiltTv.setText("倾斜：（X）" + liftViolation.getMaxYTilt() + "度   （Y）" + liftViolation.getMaxYTilt() + "度");
            createTimeTv.setText(liftViolation.getAcquisitionTime());
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onClickListener.onClick(liftViolation);
                }
            });
        }
    }
}
